package br.com.async.controller.log;

import java.util.Calendar;

import br.com.async.controller.auth.UserComponent;
import br.com.async.view.util.AsyncLogMessage;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.resource.ResourceMethod;

/*
 * teste em 11 de abril de 2013
 * Classe que realizar� log da aplia��o
 * 
 */
/**
 * @author rondymesquita
 *
 */
@Resource
public class AsyncLog {
	
	private static String message = "";
	private UserComponent userComponent;
	private LogComponent logComponent;
	
	public AsyncLog(UserComponent userComponent, LogComponent logComponent){
		this.userComponent = userComponent;
		this.logComponent = logComponent;
	}
	
	public static void setMessage(String message) {
		AsyncLog.message = message;
	}

	public void log(ResourceMethod method){		
		Log log = new Log();
		log.setMessage(message);
		log.setClassName(method.getResource().toString());
		log.setMethodName(method.getMethod().toString());
		log.setTimeLog(Calendar.getInstance());
		
		if(userComponent.getUser() != null)
			log.setUsername(userComponent.getUser().getUserName());
		else
			log.setUsername(AsyncLogMessage.USER_NULL.toString());
		
		logComponent.addLog(log);
		
//		System.out.println(log.getUsername());
//		System.out.println(log.getMessage());
//		System.out.println(log.getTimeLog().getTime());
//		System.out.println(log.getClassName());
//		System.out.println(log.getMethodName());
//		System.out.println();
	
	}
	
	

}
